package org.rency.crawler.common.enums;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * 描述: 配置类别条目<br>
 * 最近修改时间:2017/9/8 16:15<br>
 *
 * @author CaiyuRen
 * @version V1.0
 * @since 2017/9/8 16:15
 */
public enum SecLevelKind {

  /****** 系统 ******/
  IDENTITY("IDENTITY","爬虫标识","identity",String.class,FirLevelKind.SYSTEM),
  NAME("NAME", "爬虫名称", "name", String.class,FirLevelKind.SYSTEM),

  /****** 网络 ******/
  HTTP_CONNECTION_TIMEOUT("HTTP_CONNECTION_TIMEOUT","网络连接超时时间(ms)","http.connection.timeout",Long.class,FirLevelKind.INET),
  HTTP_RETRY_TIMES("HTTP_RETRY_TIMES","网络连接重试次数","http.retry.times",Integer.class,FirLevelKind.INET),
  HTTP_SOCKET_TIMEOUT("HTTP_SOCKET_TIMEOUT","网络连接Socket超时时间(ms)","http.socket.timeout",Long.class,FirLevelKind.INET),
  HTTP_ALLOW_REDIRECT("HTTP_ALLOW_REDIRECT","网络连接允许重定向(Y/N)","http.allow.redirect",String.class,FirLevelKind.INET),
  HTTP_POOL_MAX_SIZE("HTTP_POOL_MAX_SIZE","网络连接池最大大小","htp.pool.max.size",Integer.class,FirLevelKind.INET),
  HTTP_READ_TIMEOUT("HTTP_READ_TIMEOUT","网络连接读取超时时间(ms)","http.read.timeout",Long.class,FirLevelKind.INET),
  HTTP_PROXY_SWITCH("HTTP_PROXY_SWITCH","网络代理开关(Y/N)","http.proxy.switch",String.class,FirLevelKind.INET),
  HTTP_BROWSER_AGENTS("HTTP_BROWSER_AGENTS","浏览器Agent","http.browser.agents",String.class,FirLevelKind.INET),
  HTTP_FILE_CONTENT_TYPE("HTTP_FILE_CONTENT_TYPE","HTTP请求文件响应内容类型","http.file.content.type",String.class,FirLevelKind.INET),

  /****** 缓存 ******/
  ROBOTS_EXPIRE_TIME("ROBOTS_EXPIRE_TIME","Robots协议缓存失效时间(秒)","robots.expire.time",Long.class,FirLevelKind.CACHE),
  HOST_EXPIRE_TIME("HOST_EXPIRE_TIME","域名缓存失效时间(秒)","host.expire.time",Long.class,FirLevelKind.CACHE),
  FETCHED_EXPIRE_TIME("FETCHED_EXPIRE_TIME","已抓取缓存失效时间(秒)","fetched.expire.time",Long.class,FirLevelKind.CACHE),
  FETCH_EXT_EXPIRE_TIME("FETCH_EXT_EXPIRE_TIME","抓取扩展缓存失效时间(秒)","fetch.ext.expire.time",Long.class,FirLevelKind.CACHE),
  FETCH_CYCLE_SEC("FETCH_CYCLE_SEC","抓取周期(秒)","fetch.cycle.sec",Long.class,FirLevelKind.CACHE),

  /****** 抓取 ******/
  ROBOTS_SWITCH("ROBOTS_SWITCH","Robot协议开关(Y/N)","robots.switch",String.class,FirLevelKind.FETCH),
  FETCH_RETRY_TIME("FETCH_RETRY_TIME","抓取重试次数","fetch.retry.times",Integer.class,FirLevelKind.FETCH),
  FETCH_DEPTH("FETCH_DEPTH","默认抓取深度","fetch.depth",Integer.class,FirLevelKind.FETCH),
  FETCH_WEIGHT("FETCH_WEIGHT","默认抓取权重","fetch.weight",Double.class,FirLevelKind.FETCH),
  FETCH_SNAPSHOT("FETCH_SNAPSHOT","抓取快照(Y/N)","fetch.snapshot",String.class,FirLevelKind.FETCH),
  FETCH_INTERVAL_TIME("FETCH_INTERVAL_TIME","抓取同一网站间隔时间(秒)","fetch.interval.time",Long.class,FirLevelKind.FETCH),
  FETCH_IMG("FETCH_IMG","是否抓取图片(Y/N)","fetch.img",String.class,FirLevelKind.FETCH),
  FETCH_SCRIPT("FETCH_SCRIPT","是否抓取脚本(Y/N)","fetch.script",String.class,FirLevelKind.FETCH),
  FETCH_STYLE("FETCH_STYLE","是否抓取样式(Y/N)","fetch.style",String.class,FirLevelKind.FETCH),
  FETCH_SAME_SITE("FETCH_SAME_SITE","是否抓取同一网站(Y/N)","fetch.same.site",String.class,FirLevelKind.FETCH),
  FETCH_EXCLUDE_URI_PREFIX("FETCH_EXCLUDE_URI_PREFIX","抓取需过滤URI前缀","fetch.exclude.uri.prefix",String.class,FirLevelKind.FETCH),
  FETCH_EXCLUDE_URI_SUFFIX("FETCH_EXCLUDE_URI_SUFFIX","抓取需过滤URI后缀","fetch.exclude.uri.suffix",String.class,FirLevelKind.FETCH),
  ;

  private String       code;
  private String       msg;
  private String       key;
  private Class<?>     clazz;
  private FirLevelKind parent;

  SecLevelKind(String code, String msg, String key, Class<?> clazz,FirLevelKind parent){
    this.code = code;
    this.msg = msg;
    this.key = key;
    this.clazz = clazz;
    this.parent = parent;
  }

  public static SecLevelKind get(String code){
    for(SecLevelKind kind : SecLevelKind.values()){
      if(code.equalsIgnoreCase(kind.code)){
        return kind;
      }
    }
    return null;
  }

  public String getCode() {
    return code;
  }

  public String getMsg() {
    return msg;
  }

  public String getKey() {
    return key;
  }

  public Class<?> getClazz() {
    return clazz;
  }

  public FirLevelKind getParent() {
    return parent;
  }

  @Override
  public String toString() {
    return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
  }
}